import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { RenderType } from '@pkg/setting';
import {render} from "@apps/antd-admin/src/hooks/render/renderUtils";
import {Api} from "./api";
export const columns: BasicColumn[] = [
  {
    title: '优惠券名称',
    dataIndex: 'couponTitle',
    width: 180,
  },
  {
    title: '优惠卷面值',
    dataIndex: 'couponAmount',
    width: 120,
  },
  {
    title: '使用门槛',
    dataIndex: 'hasWithAmount',
    width: 80,
    dictData: [
      { label: '有', value: 1 },
      { label: '无', value: 0 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '最低使用金额',
    dataIndex: 'withAmount',
    width: 120,
  },
  {
    title: '库存数量',
    dataIndex: 'provideNum',
    width: 120,
  },
  {
    title: '剩余数量',
    dataIndex: 'surplusNum',
    width: 120,
  },
  {
    title: '开始日期',
    dataIndex: 'expiryBeginTime',
    width: 120,
  },
  {
    title: '截止日期',
    dataIndex: 'expiryEndTime',
    width: 120,
  },
  {
    title: '有效天数',
    dataIndex: 'validDays',
    width: 80,
  },
  {
    title: '发布状态',
    dataIndex: 'state',
    width: 80,
    rowKey: 'couponId',
    renderApi: Api.setCouponState,
    customRender: render.renderSwitch,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'couponTitle',
    label: '优惠券名称',
    component: 'Input',
    colProps: { span: 4 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '优惠券名称',
    field: 'couponTitle',
    component: 'Input',
    required: true,
  },
  {
    label: '优惠券面值',
    field: 'couponAmount',
    required: true,
    component: 'InputNumber',
    componentProps:{
      style:{
        width:'200px'
      }
    },
  },
  {
    field: 'hasWithAmount',
    label: '使用门槛',
    component: 'RadioGroup',
    required: true,
    componentProps: {
      options: [
        { label: '有', value: 1 },
        { label: '无', value: 0 },
      ],
    },
  },
  {
    label: '最低使用金额',
    field: 'withAmount',
    required: true,
    component: 'InputNumber',
    componentProps:{
      style:{
        width:'200px'
      }
    },
    ifShow: ({model}) => {
      if(model.hasWithAmount == 1) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '开始日期',
    field: 'expiryBeginTime',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '有效天数',
    field: 'validDays',
    component: 'InputNumber',
    componentProps:{
      style:{
        width:'200px'
      }
    },
    required: true,
  },
  {
    label: '库存数量',
    field: 'provideNum',
    component: 'InputNumber',
    required: true
  },
  {
    label: '使用说明',
    field: 'couponDesc',
    componentProps:{
      height:400
    },
    component: 'TyEditor',
  },
];
